
using System;
using System.Collections;
using System.Data;
using System.Data.SqlClient;

namespace ProcessesSMS
{	
	public class SMS_LIST
	{

		#region ***** fields & properties ***** 
		
		private System.Int32 _MO_ID;
		public System.Int32 MO_ID
		{ 
			get 
			{ 
				return _MO_ID;
			}
			set 
			{ 
				_MO_ID = value;
			}
		}


		private string _UserID;
		public string UserID
		{
			get 
			{
				return _UserID;
			}
			set
			{
				_UserID=value;
			}
		}
		private string _ServiceID;
		public string ServiceID
		{
			get 
			{
				return _ServiceID;
			}
			set
			{
				_ServiceID=value;
			}
		}
		private string _CommandCode;
		public string CommandCode
		{
			get 
			{
				return _CommandCode;
			}
			set
			{
				_CommandCode=value;
			}
		}
		private string _Message;
		public string Message
		{
			get 
			{
				return _Message;
			}
			set
			{
				_Message=value;
			}
		}
		private int _RequestID;
		public int RequestID
		{
			get 
			{
				return _RequestID;
			}
			set
			{
				_RequestID=value;
			}
		}
		private DateTime _RequestTime;
		public DateTime RequestTime
		{
			get 
			{
				return _RequestTime;
			}
			set
			{
				_RequestTime=value;
			}
		}
		private System.Int32 _Number;
		public System.Int32 Number
		{ 
			get 
			{ 
				return _Number;
			}
			set 
			{ 
				_Number = value;
			}
		}		
		private DateTime _ResponseTime;
		public DateTime ResponseTime
		{ 
			get 
			{ 
				return _ResponseTime;
			}
			set 
			{ 
				_ResponseTime = value;
			}
		}		
		#endregion

		/// <summary>
		/// SMS_MT
		/// </summary>
		public SMS_LIST()
		{
		}


		/// <summary>
		/// SMS_MT
		/// </summary>
		public SMS_LIST(System.Int32 MO_ID,System.String UserID,System.String ServiceID,System.String CommandCode,System.String Message, System.Int32 RequestID,System.DateTime RequestTime,System.Int32 Number)
		{
			this.MO_ID = MO_ID;
			this.UserID = UserID;
			this.ServiceID = ServiceID;
			this.Message = Message;
			this.CommandCode = CommandCode;
			this.RequestID = RequestID;
			this.RequestTime = RequestTime;
			this.Number = Number;
		}					
		#region *****persistance managing methods		
		/// <summary>
		/// add a record
		/// </summary>
		/// <param name="myID"></param>
		public void Insert()
		{			
				string connstr = ConfigSettings.ReadSetting("SMSConnStr");
				string reqSQL = "INSERT INTO SMS_LIST(MO_ID,UserID,ServiceID,CommandCode,Message,RequestID,RequestTime,Number)";
					reqSQL+= " VALUES(@MOID,@UserID,@ServiceID,@CommandCode,@Message,@RequestID,@RequestTime,@Number)";
				try
				{
					SqlConnection conn = new SqlConnection(connstr);
					conn.Open();
					SqlCommand oCommand;
				
					oCommand = new SqlCommand(reqSQL,conn);
					oCommand.Parameters.Clear();				
					oCommand.Parameters.Add("@MOID",MO_ID);
					oCommand.Parameters.Add("@UserID",UserID);
					oCommand.Parameters.Add("@ServiceID",ServiceID);				
					oCommand.Parameters.Add("@CommandCode",CommandCode);
					oCommand.Parameters.Add("@Message",Message);
					oCommand.Parameters.Add("@RequestID",RequestID);								
					oCommand.Parameters.Add("@RequestTime",RequestTime);
					oCommand.Parameters.Add("@Number",Number);						
					oCommand.ExecuteNonQuery();				
					conn.Close();			
										
			}
			catch(Exception myErr)
			{					
				throw(new Exception(myErr.ToString() + reqSQL));
			}
		}
		public void UpdateXoSo(int ID,DateTime responseTime)
		{
			string connstr = ConfigSettings.ReadSetting("SMSConnStr");
			string reqSQL = "UPDATE SMS_LIST SET ResponseTime = @ResponseTime WHERE ID = @ID";			
			try
			{
				SqlConnection conn = new SqlConnection(connstr);
				conn.Open();
				SqlCommand oCommand;
				
				oCommand = new SqlCommand(reqSQL,conn);
				oCommand.Parameters.Clear();				
				oCommand.Parameters.Add("@ID",ID);		
				oCommand.Parameters.Add("@ResponseTime",responseTime);	
				oCommand.ExecuteNonQuery();				
				conn.Close();			
										
			}
			catch(Exception myErr)
			{					
				throw(new Exception(myErr.ToString() + reqSQL));
			}
		}
		#endregion
	}
 }
